<?php

	include("common.php");
	
	$result = mysql_query("SELECT * FROM `197_articles`");
	$articles = array();
	while($row = mysql_fetch_assoc($result)){
		array_push($articles, $row);
	}
	
?>
<?php include("header.php"); ?>
<h1>修改／刪除作文</h1>
<div id="delete-article-dialog">
	<p>確定刪除？</p>
</div>
<script type="text/javascript" defer="defer">
	$("#delete-article-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "刪除作文",
		modal: true,
		draggable: false,
		resizable: false
	});
	function showConfirm(article_id){
		$("#delete-article-dialog").dialog("option", "buttons", {"確定": function(){ $(this).dialog("close"); deleteArticle(article_id); }, "取消": function(){ $(this).dialog("close"); }
		}).dialog("open");
	}
	function deleteArticle(article_id){
		$("#delete-article-dialog").dialog("option", "buttons", { "關閉": function(){ location.reload(); } });
		$("#delete-article-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#delete-article-dialog").dialog("open");
		$("#delete-article-dialog").load("articleDelete.php?article_id=" + article_id + "&ajax=true");
	}
</script>
<?php if(empty($articles)){ ?>
	<p>目前沒有作文。</p>
<?php } else { ?>
	<ul>
		<?php foreach($articles as $row){ ?>
			<li><?php echo $row['title']; ?> - [ <a href="articleEdit.php?article_id=<?php echo $row['article_id']; ?>">編輯</a>｜<a href="articleDelete.php?article_id=<?php echo $row['article_id']; ?>" onclick="showConfirm(<?php echo $row['article_id']; ?>); return false;">刪除</a> ]</li>
		<?php } ?>
	</ul>
<?php } ?>
<p><a href="articleAdd.php">新增</a></p>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>